/*
 ============================================================================
 Name        : cyclic_buffer.c
 Author      :
 Version     :
 Copyright   : Your copyright notice
 Description : Attempt to implement of cyclic buffer in C, but as C++ art, Ansi-style
 ============================================================================
 */

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <windows.h>
# include "cbuffer.h"

typedef struct {
	time_t current_time;
	long value;
} CHUNK;

int main(void) {

	CBUFFER *pcb = cb(5, sizeof (CHUNK));
	short i;
	CHUNK ch;
	for (i = 0; i < 7; i++ ) {
		time (&ch.current_time);
		ch.value = i;
		pcb->write (pcb, &ch);
		Sleep (1000);
	}

	CHUNK *pch;
	struct tm *timeinfo;
	while ( (pch = pcb->read(pcb)) != 0) {
		long i = pch->value;
		time_t t = pch->current_time;
		timeinfo = localtime(&t);
		printf ("index = %ld; hours = %d; minutes = %d; seconds = %d",
				i, timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);
	}

	puts("!!!Hello World!!!"); /* prints !!!Hello World!!! */
	_cb(pcb);
	return EXIT_SUCCESS;
}
